package com.zqxq.lottery.api.controller;

import com.baomidou.mybatisplus.plugins.Page;
import com.zqxq.common.constant.Result;
import com.zqxq.common.enums.CodeEnum;
import com.zqxq.lottery.api.feign.LotteryServerFeignClient;
import com.zqxq.lottery.entity.bo.sys.SysNewsCMSBO;
import com.zqxq.lottery.entity.vo.sys.SysNewsVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description ：
 * @Author ： 解风
 * @Date ： 2018/03/22 11:06
 */
@Api(value = "资讯接口",tags = "资讯接口")
@RestController
@Slf4j
@RequestMapping(value = "/news", produces = "application/json")
public class NewsController {

    @Autowired
    private LotteryServerFeignClient lotteryServerFeignClient;

    @ApiOperation("分页获取咨询列表")
    @PostMapping("/queryPageList")
    public Result<Page<SysNewsVO>> queryNewsPageList(SysNewsCMSBO baseBO){
        return lotteryServerFeignClient.queryNewsPageList(baseBO);
    }
    @ApiOperation("保存阅读数")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "主键", required = true, paramType = "query", dataType = "Long")
    })
    @PostMapping("/saveReaderNum")
    public Result saveReaderNum(Long id){
        if(id == null){
            return new Result(CodeEnum.FAIL_100002.getCode(), CodeEnum.FAIL_100002.getMsg());
        }
        return lotteryServerFeignClient.saveReaderNum(id);
    }

    @ApiOperation("获取咨询详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "主键", required = true, paramType = "query", dataType = "Long")
    })
    @PostMapping("/getNews")
    public Result<SysNewsVO> getNews(Long id){
        if(id == null){
            return new Result(CodeEnum.FAIL_100002.getCode(), CodeEnum.FAIL_100002.getMsg());
        }
        return lotteryServerFeignClient.getNews(id);
    }
}
